/*
 * Created on Jan 16, 2005
 */
package org.vectrics.recruiter.struts;

import javax.servlet.jsp.JspException;

import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.user.CandidateInfo;
import org.vectrics.struts.Request;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;
import org.vectrics.user.Person;

/**
 * @author mmoore
 */
public class RemoveProfileAction extends VectricsStrutsAction {

    protected String doExecute(VectricsActionData actionData) throws JspException {
        Request request = actionData.getRequest();
        String personIdParam = request.getParameter("personId");

        Long personId = new Long(personIdParam);
        Person person = CoreServiceLocator.getPersonService().findPersonById(personId);
        // person.removeRole("recruit-candidate", null);
        CandidateInfo candidateInfo = RecruitServiceLocator.getRecruitUserService().findCandidateInfo(person);
        if (candidateInfo != null) {
            RecruitServiceLocator.getRecruitUserService().removeJobAgents(candidateInfo);

            candidateInfo.setVoided(true);
            candidateInfo.setOkToContact(false);
            candidateInfo.setLookingContract(false);
            candidateInfo.setLookingFullTime(false);
            candidateInfo.setLookingPartTime(false);
            candidateInfo.setLookingPermanent(false);
            RecruitServiceLocator.getRecruitUserService().updateCandidateInfo(candidateInfo);

            // Remove user credentials, but don't remove person.
            if (person.getPrivileges().size() == 1) {
                person.setUser(null);
                CoreServiceLocator.getPersonService().updatePerson(person);
            }
        }

        return ("success");
    }

}
